LIBRARY_PATH = /usr/local/lib
INCLUDE_PATH = /usr/local/include

#########Compilation Flags#######################################

CXXFLAGS+=-DMILI_NAMESPACE -Wall -Wextra -I.

INCLUDES = feca/storage_policies.h feca/loading_policies.h feca/cache.h feca/feca.h

CXX = g++

ifeq ($(DEBUG),on)
	CXXFLAGS+= -ggdb3
endif

ifeq ($(STL_DEBUG_ENABLE),on)
	CXXFLAGS+= -ggdb3 -DSTL_DEBUG_ENABLE
endif

feca: $(OBJECTS)
	 $(CXX) -shared -Wl,-soname,libfeca.so.1 -o libfeca.so.1.0 $(OBJECTS)

all: feca

.PHONY: cleanall cleanobj install

clean: cleanall

cleanall : cleanobj 

cleanobj :
	rm -f *.o */*.o */*/*.o */*/*/*.o
	rm -f libfeca.so.1.0

install:
	mkdir -p $(INCLUDE_PATH)/feca
	cp $(INCLUDES) $(INCLUDE_PATH)/feca
	ldconfig


# Find all sources with available tests
TEST_SRCS := $(patsubst ./%, %, $(shell find|egrep "_test\.cpp$$") )
TEST_BINS := $(patsubst %.cpp, %, $(TEST_SRCS))

test:
	@# Run all tests
	for TEST in $(TEST_BINS); do \
		make "$$TEST"_run; \
	done

%_test: %_test.cpp
	@# Compile the source and link with the real .o
	g++ $(CXXFLAGS) $(LDFLAGS) \
		-lgtest_main -lgmock -lpthread -o $@ \
			$(OBJECTS) $@.cpp 

%_test_run: %_test
	@# Zomg magic magic - this will make the test and then run it
	./$<
